<!-- 批改试卷 -->

<template>
  <div>
    <el-table border :data="paper" stripe :header-cell-style="{background:'#DCDCDC',color:'#0f0f0f'}">
      <el-table-column prop="id" label="题目ID" width="80" sortable>
      </el-table-column>
      <el-table-column prop="name" label="题目名称">
      </el-table-column>
      <el-table-column prop="type" label="题目类型" width="150">
        <template v-slot="scope">
          <span v-if="scope.row.type === 1">选择题</span>
          <span v-if="scope.row.type === 2">判断题</span>
          <span v-if="scope.row.type === 3">问答题</span>
        </template>
      </el-table-column>
      <el-table-column prop="a" label="A">
      </el-table-column>
      <el-table-column prop="b" label="B">
      </el-table-column>
      <el-table-column prop="c" label="C">
      </el-table-column>
      <el-table-column prop="d" label="D">
      </el-table-column>
      <el-table-column prop="score" label="分数">
      </el-table-column>
      <el-table-column prop="answer" label="标准答案">
      </el-table-column>
      <el-table-column prop="studentAnswer" label="学生答案">
      </el-table-column>
<!--      <el-table-column prop="detail" label="解析">-->
<!--      </el-table-column>-->
      <el-table-column prop="studentScore" label="得分" width="100">
        <template v-slot="scope">
          <span v-if="scope.row.type === 1 || scope.row.type === 2" style="color: red">{{
              scope.row.studentScore
            }}</span>
          <el-input v-if="scope.row.type === 3" v-model="scope.row.studentScore" clearable></el-input>
        </template>
      </el-table-column>
    </el-table>

    <div style="text-align: center;margin: 30px auto">
      <el-button style="font-size: 20px;height: 50px" type="primary" @click="submitScore">批 改 完 成</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "Tea_CorrectingPapers",
  data() {
    return {
      sp: this.$route.query.sp,
      paper: []
    }
  },
  created() {
    this.request.get("/s-p/" + this.sp).then(res => {
      this.paper = JSON.parse(res.paper)
      if (this.paper && this.paper.length) {
        // 自动阅卷
        this.paper.forEach(item => {
          if (item.type === 1 || item.type === 2) {
            item.studentScore = 0
            if (item.answer === item.studentAnswer) {
              item.studentScore = item.score
            }
          }
        })
      }
    })
  },
  methods: {
    submitScore() {
      let sum = 0

      this.paper.forEach(item => {
        if (item.studentScore == null) {
          item.studentScore = 0
        }
        sum += parseInt(item.studentScore)
      })

      this.request.post("/s-p/", {id: this.sp, score: sum}).then(res => {
        this.$message.success("批改成功！")
        this.$router.push("/System_TeaBackend/Management_Marking")
      })
    }
  }
}
</script>

<style scoped>

</style>